package com.jock.zjaddressanddatepicker;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.android.pc.ioc.inject.InjectBinder;
import com.android.pc.ioc.inject.InjectInit;
import com.android.pc.ioc.inject.InjectLayer;
import com.android.pc.ioc.inject.InjectView;
import com.android.pc.ioc.view.listener.OnClick;
import com.jock.zjaddressanddatepicker.pickerview.OptionsPickerViewFactory;
import com.jock.zjaddressanddatepicker.pickerview.view.OptionsPickerView;
import com.jock.zjaddressanddatepicker.pickerview.view.TimePickerView;

/**
 * author: Jock.Lin on 2016/8/15 0015 下午 4:50.
 * email: Jock_Jan@yeah.net
 * */

@InjectLayer(R.layout.activity_main)
public class MainActivity extends Activity {


    private OptionsPickerView addressOptions;
    private TimePickerView dateOptions;
    private Activity mContext;

    @InjectView(binders = @InjectBinder(method = "onClick", listeners = {OnClick.class}))
    private TextView tvTimeBtn, tvAddressOptions;

    @InjectInit
    private void init(){
        mContext = MainActivity.this;
        addressOptions = new OptionsPickerViewFactory().builtAddressOptionsPickerView(mContext,onPickerLitener);
        dateOptions    = new OptionsPickerViewFactory().builtDateOptionsPickerView	 (mContext,dateOptionsPickerLitener);
    }

    OptionsPickerViewFactory.OptionsPickerLitener onPickerLitener = new OptionsPickerViewFactory.OptionsPickerLitener() {

        @Override
        public void onPickerLitener(String province, String city, String district) {
            String address = province + city + district;
            tvAddressOptions.setText("选择地址：" + address);
        }
    };

    OptionsPickerViewFactory.DateOptionsPickerLitener dateOptionsPickerLitener = new OptionsPickerViewFactory.DateOptionsPickerLitener() {

        @Override
        public void onDatePickerLitener(String date) {
            tvTimeBtn.setText("选择时间：" + TimeUtil.millisToStringDate(TimeUtil.string2Millis(date, "yyyy年MM月dd日"), "yyyy-MM-dd"));
        }
    };

    public void onClick(View v){
        switch (v.getId()){
            case R.id.tvTimeBtn:
                dateOptions.show();
                break;
            case R.id.tvAddressOptions:
                addressOptions.show();
                break;
        }
    }
}
